package com.resou.reader.data.tinder.local;

import android.content.Context;

import com.resou.reader.ReSouApplication;
import com.resou.reader.data.tinder.tinder.SlideBean;
import com.resou.reader.utils.diskcache.DiskCache;

import java.util.ArrayList;
import java.util.List;

public class TinderLocalDataSource {
    public static final String PENDING_SUBMIT_SLIDE = "pending_submit_slide";
    private static TinderLocalDataSource sInstance;

    private TinderLocalDataSource(Context context) {
    }

    public static TinderLocalDataSource getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new TinderLocalDataSource(context);
        }
        return sInstance;
    }

    /**
     * 保存到本地
     *
     * @param slideBean bean
     */
    public void saveToLocalSlideBean(SlideBean slideBean) {
    }

    /**
     * 添加到待提交列表，待下次提交
     * @param slideBean
     */
    public void addToPendingSubmission(SlideBean slideBean) {
        //先读取，
        List<SlideBean> slideBeans = loadPendingSubmitSlideBean();
        if (slideBeans == null) {
            slideBeans = new ArrayList<>();
        }
        // 保存
        slideBeans.add(slideBean);
        // 写入
        DiskCache.asyncWriteCache(PENDING_SUBMIT_SLIDE, slideBeans, null);
    }

    public List<SlideBean> loadLocalSlideBeans() {
        return null;
    }

    public void deleteLocalCache(String bookId) {

    }

    /**
     * 加载待提交列表
     */
    public List<SlideBean> loadPendingSubmitSlideBean() {
       return DiskCache.syncReadListCache(PENDING_SUBMIT_SLIDE);
    }

    public void clearCache() {
    }
}
